package com.ym.jiujiangeyou.adapter;

import java.util.List;


import com.ym.jiujiangeyou.R;
import com.ym.jiujiangeyou.adapter.HotelListAdapter.ViewHolder;
import com.ym.jiujiangeyou.bitmap.ImageLoader;
import com.ym.jiujiangeyou.entity.Food;
import com.ym.jiujiangeyou.entity.Hotel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
 /**   
 * @author 叶铭   
 * @email yeming_1001@163.com
 * @version V1.0   
* @Description: 美食列表适配器 
*/
public class FoodListAdapter extends BaseAdapter {
	
	private LayoutInflater inflater;
	private Context context;
	private ImageLoader loader ;
	private List<Food> list;
	
	public FoodListAdapter(Context context) {
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		loader = new ImageLoader(context) ;
	//	loader.setDefaultBitmap(context.getResources().getDrawable(R.drawable.ic_empty)) ;
	}
	
	public void setData(List<Food> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();

	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);

	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;

	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.food_item, null);
			viewHolder.imageView = (ImageView) convertView
					.findViewById(R.id.food_pic);
			viewHolder.textView1 = (TextView) convertView
					.findViewById(R.id.food_name);
			viewHolder.textView2 = (TextView) convertView
					.findViewById(R.id.food_introduct);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.textView1.setText(list.get(position).getName().toString());
		viewHolder.textView2
				.setText(list.get(position).getIntroduct());
		/*imageLoad.loadImage(list.get(position).getUrl().toString(),
				viewHolder.imageView);*/
		loader.DisplayImage(list.get(position).getUrl().toString(), viewHolder.imageView, false) ;
		return convertView;

	}
	
	class ViewHolder {
		ImageView imageView;
		TextView textView1, textView2;
	}


}
